﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OleDb;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Js_Study.GoogleMap
{
    public partial class mapAPI : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btn1_Click(object sender, EventArgs e)
        {
            string val = hid.Value.ToString();

           
        }

        public DataSet LoadDataFromExcel(string filePath)
        {
            try
            {
                string strConn;
                strConn = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties='Excel 8.0;HDR=Yes;IMEX=1;'", filePath);
                OleDbConnection OleConn = new OleDbConnection(strConn);
                OleConn.Open();
                String sql = "SELECT * FROM [citiinfo$]";//可是更改Sheet名称，比如sheet2，等等  

                OleDbDataAdapter OleDaExcel = new OleDbDataAdapter(sql, OleConn);
                DataSet OleDsExcle = new DataSet();
                OleDaExcel.Fill(OleDsExcle, "citiinfo");
                OleConn.Close();
                return OleDsExcle;
            }
            catch (Exception ex)
            {
                string msg = ex.Message;
                return null;
            }
        }

        protected void load_excel_Click(object sender, EventArgs e)
        {
            DataSet ds = LoadDataFromExcel(Server.MapPath("citiinfo.xlsx"));
            DataTable dt = ds.Tables[0].Columns["CITY"].Table;

            string str = "";

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                str += dt.Rows[i]["CITY"].ToString() + ",";
            }

            str = str.Substring(0, str.Length - 1);

            hid.Value = str;
        }
    }
}